package cheme.ProcessEditor;

import org.eclipse.draw2d.PositionConstants;
import org.eclipse.gef.GraphicalEditPart;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyEvent;

public class KeyNavigator extends AbstractKeyProcess
{
	@Override
	public boolean handleKey(KeyEvent event, GraphicalEditPart focusPart)
	{
		super.handleKey(event, focusPart);
		
		if ((event.stateMask & SWT.CONTROL) == 0)
		{
			switch (event.keyCode)
			{
				case SWT.ARROW_LEFT:
				{
					if(LeafFigureNavigator.navigateNearestSibling(getFocusPart(), PositionConstants.WEST))
					{
						return true;
					}
					break;
				}
				case SWT.ARROW_RIGHT:
				{
					if(LeafFigureNavigator.navigateNearestSibling(getFocusPart(), PositionConstants.EAST))
					{
						return true;
					}
					break;
				}
				case SWT.ARROW_UP:
				{
					if(LeafFigureNavigator.navigateNearestSibling(getFocusPart(), PositionConstants.NORTH))
					{
						return true;
					}
					break;
				}
				case SWT.ARROW_DOWN:
				{
					if(LeafFigureNavigator.navigateNearestSibling(getFocusPart(), PositionConstants.SOUTH))
					{
						return true;
					}
					break;
				}
				case SWT.HOME:
				{
					if (LeafFigureNavigator.navigateFarthestSibling(getFocusPart(), PositionConstants.WEST))
					{
						return true;
					}
					break;
				}
				case SWT.END:
				{
					if (LeafFigureNavigator.navigateFarthestSibling(getFocusPart(), PositionConstants.EAST))
					{
						return true;
					}
					break;
				}
				case SWT.PAGE_DOWN:
				{
					if (LeafFigureNavigator.navigateFarthestSibling(getFocusPart(), PositionConstants.SOUTH))
					{
						return true;
					}
					break;
				}
				case SWT.PAGE_UP:
				{
					if (LeafFigureNavigator.navigateFarthestSibling(getFocusPart(), PositionConstants.NORTH))
					{
						return true;
					}
				}
			}
		}
		
		return false;
	}
}
